<?php
require_once('includes/bootstrap.php');

if (strpos($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST']) === false
	|| empty($_GET['code']))
{
	exit('location:  ' . APPLICATION_URL);
	exit;
}

$code = filter_input(INPUT_GET, 'code', FILTER_SANITIZE_STRING);

// Check the item exists
$req = mysql_query('SELECT * FROM items where code="' . mysql_real_escape_string($code) . '"');

if (!$row = mysql_fetch_assoc($req))
{
	exit('location:  ' . APPLICATION_URL);
	exit;
}

if (empty($_SESSION['commande'][$code]))
{
	$_SESSION['commande'][$code] = $row;
	$_SESSION['commande'][$code]['quantity'] = 0;
}

$_SESSION['commande'][$code]['quantity']++;

$_SESSION['just_added'] = $row;

header('location:  ' . APPLICATION_URL);

